package com.example.myapplication.tabFragments;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.activitys.ArticleActivity;
import com.example.myapplication.activitys.AttractionsActivity;
import com.example.myapplication.activitys.PoiAroundSearchActivity;
import com.example.myapplication.activitys.SelectActivity;
import com.example.myapplication.adapters.VerticalBannerAdapter;
import com.example.myapplication.bean.BannerBean;
import com.example.myapplication.library.VerticalBannerView;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.bgabanner.BGABanner;

public class HomeFragment extends Fragment implements View.OnClickListener {

    BGABanner bgaBanner;

    VerticalBannerView bannerView;

    LinearLayout attractions_lin, article_lin, food_lin, hotel_lin;
    CheckBox home_location_cbx;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        return View.inflate(getActivity(), R.layout.fragment_home, null);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
    }


    private void initView(View view) {
        bgaBanner = view.findViewById(R.id.banner_guide_content);
        bannerView = view.findViewById(R.id.banner);
        home_location_cbx = view.findViewById(R.id.home_location_cbx);
        attractions_lin = view.findViewById(R.id.attractions_lin);
        article_lin = view.findViewById(R.id.article_lin);
        hotel_lin = view.findViewById(R.id.article_hotel_lin);
        food_lin = view.findViewById(R.id.article_food_lin);
        food_lin.setOnClickListener(this);
        home_location_cbx.setOnClickListener(this);
        hotel_lin.setOnClickListener(this);
        attractions_lin.setOnClickListener(this);
        article_lin.setOnClickListener(this);
        bgaBanner.setAdapter(new BGABanner.Adapter() {
            @Override
            public void fillBannerItem(BGABanner banner, View itemView, @Nullable Object model, int position) {
                Glide.with(getActivity())
                        .load(model)
                        .into((ImageView) itemView);
            }
        });
    }

    private void initData() {
        List<Integer> list = new ArrayList<>();
        list.add(R.mipmap.timg);
        list.add(R.mipmap.timga);
        list.add(R.mipmap.timgb);
        list.add(R.mipmap.timgc);
        bgaBanner.setData(list, null);

        List<BannerBean> bannerBeans = new ArrayList<>(9);
        bannerBeans.add(new BannerBean("泰山—非物质文化遗产"));
        bannerBeans.add(new BannerBean("太行至尊—王莽岭，清凉圣境，康养圣地"));
        bannerBeans.add(new BannerBean("一日寻奇百里峡，终生难忘野山坡—野山坡"));
        bannerBeans.add(new BannerBean("面朝大海春暖花开"));
        bannerBeans.add(new BannerBean("不到长城非好汉"));
        bannerBeans.add(new BannerBean("品味好客山东"));
        bannerBeans.add(new BannerBean("太行至尊—王莽岭，清凉圣境，康养圣地"));
        bannerBeans.add(new BannerBean("诚仪燕赵，圣境河北"));
        bannerBeans.add(new BannerBean("一日寻奇百里峡，终生难忘野山坡—野山坡"));

        bannerView.setAdapter(new VerticalBannerAdapter(bannerBeans));
        bannerView.start();
    }

    @Override
    public void onResume() {
        super.onResume();
        home_location_cbx.setText(MainActivity.CityNmae);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.home_location_cbx:
                startActivity(new Intent(getActivity(), SelectActivity.class));
                break;
            case R.id.attractions_lin:
                startActivity(new Intent(getActivity(), AttractionsActivity.class));
                break;
            case R.id.article_lin:
                startActivity(new Intent(getActivity(), ArticleActivity.class));

                break;
            case R.id.article_food_lin:
                Intent intent = new Intent(getActivity(), PoiAroundSearchActivity.class);
                intent.putExtra("key", "美食");
                startActivity(intent);
                break;
            case R.id.article_hotel_lin:
                Intent intent1 = new Intent(getActivity(), PoiAroundSearchActivity.class);
                intent1.putExtra("key", "宾馆");
                startActivity(intent1);
                break;
        }
    }
}
